home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / MSG Graphic Effects 1.0 Source / Four-corner scroll.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-23  |  5.6 KB  |  168 lines  |  [TEXT/KAHL]

  1. /*******************************************************************************
  2.  * Copyright © 1992-1993 Mark Pilgrim                                          *
  3.  *                                                                             *
  4.  * This file is provided as is, and may be freely distributed unaltered.  This *
  5.  * message must accompany any copy of this file.  This file may be used or     *
  6.  * modified for use for a non-commercial product provided that appropriate     *
  7.  * credit is given to the author named above.                                  *
  8.  * Commercial use of this source code is prohibited.                           *
  9.  ******************************************************************************/
  10.  
  11. #include "msg misc.h"
  12. #include "msg timing.h"
  13.  
  14. #define        BoxSize        10
  15. #define CorrectTime 4
  16.  
  17. void FourCornerScroll(GrafPtr);
  18.  
  19. /* Four scrolls in one, each confined to a section of the screen which includes
  20.    the center and one side, and all four scrolls moving towards the center.
  21.    Kinda slow on my Mac IIci in 8-bit; fine in 4-bit or fewer. */
  22.    
  23. void FourCornerScroll(GrafPtr sourceGrafPtr)
  24. {
  25.     int            x;
  26.     Rect        theTopRect, topdest, theBottomRect, bottomdest;
  27.     Rect        theLeftRect, leftdest, theRightRect, rightdest;
  28.     Rect        topscrollsource, topscrolldest, bottomscrollsource, bottomscrolldest;
  29.     Rect        leftscrollsource, leftscrolldest, rightscrollsource, rightscrolldest;
  30.     RgnHandle    toprgn,bottomrgn,leftrgn,rightrgn;
  31.     int            cx,cy;
  32.     int            HBoxSize=BoxSize*MAIN_WINDOW_WIDTH/MAIN_WINDOW_HEIGHT;
  33.     
  34.     cx = MAIN_WINDOW_WIDTH / 2;
  35.     cy = MAIN_WINDOW_HEIGHT / 2;
  36.  
  37.     toprgn=NewRgn();
  38.     SetEmptyRgn(toprgn);
  39.     MoveTo(0,0);
  40.     OpenRgn();                               /* top region */
  41.         LineTo(MAIN_WINDOW_WIDTH,0);
  42.         LineTo(cx,cy);
  43.         LineTo(0,0);
  44.     CloseRgn(toprgn);
  45.     
  46.     bottomrgn=NewRgn();
  47.     SetEmptyRgn(bottomrgn);
  48.     MoveTo(0,MAIN_WINDOW_HEIGHT);
  49.     OpenRgn();                               /* bottom region */
  50.         LineTo(MAIN_WINDOW_WIDTH,MAIN_WINDOW_HEIGHT);
  51.         LineTo(cx,cy);
  52.         LineTo(0,MAIN_WINDOW_HEIGHT);
  53.     CloseRgn(bottomrgn);
  54.     
  55.     leftrgn=NewRgn();
  56.     SetEmptyRgn(leftrgn);
  57.     MoveTo(0,0);
  58.     OpenRgn();                               /* left region */
  59.         LineTo(0,MAIN_WINDOW_HEIGHT);
  60.         LineTo(cx,cy);
  61.         LineTo(0,0);
  62.     CloseRgn(leftrgn);
  63.     
  64.     rightrgn=NewRgn();
  65.     SetEmptyRgn(rightrgn);
  66.     MoveTo(MAIN_WINDOW_WIDTH,0);
  67.     OpenRgn();                               /* right region */
  68.         LineTo(MAIN_WINDOW_WIDTH,MAIN_WINDOW_HEIGHT);
  69.         LineTo(cx,cy);
  70.         LineTo(MAIN_WINDOW_WIDTH,0);
  71.     CloseRgn(rightrgn);
  72.     
  73.     topscrollsource=bottomscrollsource=leftscrollsource=rightscrollsource=
  74.         topdest=bottomdest=leftdest=rightdest=gMainWindow->portRect;
  75.     
  76.     topscrollsource.bottom-=cy+BoxSize;
  77.     topscrolldest = topscrollsource;
  78.     OffsetRect(&topscrolldest, 0, BoxSize);        /* dest. strip for top scroll */
  79.     
  80.     topdest.bottom=BoxSize;                        /* dest. strip for new data on top */
  81.     
  82.     theTopRect.top=cy-BoxSize;                     /* source strip for new data on top */
  83.     theTopRect.bottom=cy;
  84.     theTopRect.left=0;
  85.     theTopRect.right=MAIN_WINDOW_WIDTH;
  86.     
  87.     bottomscrollsource.top+=cy+BoxSize;
  88.     bottomscrolldest=bottomscrollsource;
  89.     OffsetRect(&bottomscrolldest, 0, -BoxSize);
  90.     
  91.     bottomdest.top=bottomdest.bottom-BoxSize;
  92.     
  93.     theBottomRect.top=cy;
  94.     theBottomRect.left=0;
  95.     theBottomRect.bottom=cy+BoxSize;
  96.     theBottomRect.right=MAIN_WINDOW_WIDTH;
  97.     
  98.     leftscrollsource.right-=cx+HBoxSize;
  99.     leftscrolldest=leftscrollsource;
  100.     OffsetRect(&leftscrolldest,HBoxSize,0);
  101.     
  102.     leftdest.right=HBoxSize;
  103.     
  104.     theLeftRect.top=0;
  105.     theLeftRect.bottom=MAIN_WINDOW_HEIGHT;
  106.     theLeftRect.left=cx-HBoxSize;
  107.     theLeftRect.right=cx;
  108.     
  109.     rightscrollsource.left+=cx+HBoxSize;
  110.     rightscrolldest=rightscrollsource;
  111.     OffsetRect(&rightscrolldest,-HBoxSize,0);
  112.     
  113.     rightdest.left=rightdest.right-HBoxSize;
  114.     
  115.     theRightRect.top=0;
  116.     theRightRect.bottom=MAIN_WINDOW_HEIGHT;
  117.     theRightRect.left=cx;
  118.     theRightRect.right=cx+HBoxSize;
  119.     
  120.     /* for each section (top, bottom, left, right) we need to do the scroll part,
  121.     which takes a section of the dest. window and moves it, then we need to copy
  122.     in the new data from the source window */
  123.     for(x = cy - BoxSize; x >= 0; x -= BoxSize)
  124.     {
  125.         StartTiming();
  126.         CopyBits(&(gMainWindow->portBits), &(gMainWindow->portBits),
  127.                 &topscrollsource, &topscrolldest, 0, toprgn);
  128.         CopyBits(&(sourceGrafPtr->portBits), &(gMainWindow->portBits),
  129.                 &theTopRect, &topdest, 0, toprgn);
  130.         theTopRect.bottom-=BoxSize;
  131.         theTopRect.top-=BoxSize;
  132.         
  133.         CopyBits(&(gMainWindow->portBits), &(gMainWindow->portBits),
  134.                 &bottomscrollsource, &bottomscrolldest, 0, bottomrgn);
  135.         CopyBits(&(sourceGrafPtr->portBits), &(gMainWindow->portBits),
  136.                 &theBottomRect, &bottomdest, 0, bottomrgn);
  137.         theBottomRect.top+=BoxSize;
  138.         theBottomRect.bottom+=BoxSize;
  139.         
  140.         CopyBits(&(gMainWindow->portBits), &(gMainWindow->portBits),
  141.                 &leftscrollsource, &leftscrolldest, 0, leftrgn);
  142.         CopyBits(&(sourceGrafPtr->portBits), &(gMainWindow->portBits),
  143.                 &theLeftRect, &leftdest, 0, leftrgn);
  144.         theLeftRect.left-=HBoxSize;
  145.         theLeftRect.right-=HBoxSize;
  146.         
  147.         CopyBits(&(gMainWindow->portBits), &(gMainWindow->portBits),
  148.                 &rightscrollsource, &rightscrolldest, 0, rightrgn);
  149.         CopyBits(&(sourceGrafPtr->portBits), &(gMainWindow->portBits),
  150.                 &theRightRect, &rightdest, 0, rightrgn);
  151.         theRightRect.left+=HBoxSize;
  152.         theRightRect.right+=HBoxSize;
  153.         
  154.         TimeCorrection(CorrectTime);
  155.     }
  156.     
  157.     theTopRect.top=theTopRect.left=0;
  158.     theTopRect.bottom=MAIN_WINDOW_HEIGHT;
  159.     theTopRect.right=MAIN_WINDOW_WIDTH;
  160.     topdest=gMainWindow->portRect;
  161.     CopyBits(&(sourceGrafPtr->portBits), &(gMainWindow->portBits),
  162.         &theTopRect, &topdest, 0, 0L);    /* in case we missed any bits */
  163.  
  164.     DisposeRgn(toprgn);
  165.     DisposeRgn(bottomrgn);
  166.     DisposeRgn(leftrgn);
  167.     DisposeRgn(rightrgn);
  168. }